package com.wanmait.recruit.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.pojo.Industry;
import com.wanmait.recruit.service.IndustryService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@Transactional
@RequestMapping("/manage/industry")
public class IndustryController {
    @Resource
    private IndustryService industryService;
    @RequestMapping("industryList")
    public void industryList(){

    }
    @RequestMapping("industryListData")
    public ModelAndView industryListData(String name,Integer pageNum){
        ModelAndView modelAndView = new ModelAndView();
        PageInfo<Industry> pageInfo = industryService.finAll(name, pageNum);
        modelAndView.addObject("pageInfo",pageInfo);
        modelAndView.setViewName("/manage/industry/industryListData");
        return modelAndView;
    }
    @RequestMapping("delete")
    public String delete(Integer id){
        industryService.deleteById(id);
        return "redirect:/manage/industry/industryList";
    }
    @PostMapping("insert")
    public String insert(String industryName,Integer heat){
        Industry industry = new Industry();
        industry.setIndustryName(industryName);
        industry.setHeat(heat);
        industryService.insert(industry);
        return "redirect:/manage/industry/insert";
    }
    @RequestMapping("insert")
    public void insert(){
        
    }
    @RequestMapping("isRename")
    @ResponseBody
    public String isRename(String industryName){
        Boolean flag = industryService.isRename(industryName);
        if(flag){
            return "1";
        }else{
            return "0";
        }
    }
}
